<template>
  <el-card class="view-height min-view-height">
    <search-form :model="searchForm" @search="search" @reset="search">
      <el-form-item label="人事编号">
        <el-input
          v-model="searchForm.number"
          size="small"
          clearable
          maxlength="20"
        />
      </el-form-item>
      <el-form-item label="姓名">
        <el-input
          v-model="searchForm.name"
          size="small"
          clearable
          maxlength="20"
        />
      </el-form-item>
    </search-form>
    <el-row class="button-group">
      <el-button type="primary" size="small" @click="add">添 加</el-button>
    </el-row>
    <el-tabs v-model="currentTabName" @tab-click="tabClick">
      <el-tab-pane
        v-for="item in panes"
        :key="item.key"
        :label="item.label"
        :name="item.key"
      >
        <el-row class="table-container">
          <abstract-table
            v-if="currentTabName === item.key"
            :height="tableMaxHeight"
            :data="tableData"
          >
            <el-table-column
              align="center"
              label="人事编号"
              prop="number"
              show-overflow-tooltip
            />
            <el-table-column
              align="center"
              label="姓名"
              prop="name"
              show-overflow-tooltip
            />
            <el-table-column
              align="center"
              label="手机"
              prop="tel"
              show-overflow-tooltip
            />
            <el-table-column
              align="center"
              label="邮箱"
              prop="email"
              show-overflow-tooltip
            />
            <el-table-column
              align="center"
              label="角色"
              prop="role"
              show-overflow-tooltip
            />
            <el-table-column
              v-if="item.key === '2'"
              align="center"
              label="所在科室"
              prop="role"
              show-overflow-tooltip
            />
            <el-table-column
              align="center"
              label="添加时间"
              prop="addTime"
              show-overflow-tooltip
            />
            <el-table-column
              v-if="item.key === '3'"
              width="250"
              align="center"
              label="操作"
            >
              <el-button type="text" size="small" @click="leave"
                >离职</el-button
              >
              <el-button type="text" size="small" @click="leave"
                >指定科室</el-button
              >
            </el-table-column>
          </abstract-table>
          <abstract-pagination
            :model="searchForm"
            @current-change="pageChange"
            @size-change="pageSizeChange"
          ></abstract-pagination>
        </el-row>
      </el-tab-pane>
    </el-tabs>
    <add-dialog v-model="addDialog" />
  </el-card>
</template>

<script>
import SearchForm from '@/components/form/Search'
import AddDialog from './components/AddDialog.vue'

import tablePageMixin from '@/mixin/tablePageMixin'
import autoAdaptHeightMixin from '@/views/_common/ListPage/autoAdaptHeightMixin'

export default {
  components: { SearchForm, AddDialog },

  mixins: [tablePageMixin, autoAdaptHeightMixin],

  data: () => ({
    addDialog: false,
    searchForm: {
      page: 1,
      pageSize: 10,
      total: 0
    },
    currentTabName: '1',
    panes: [
      {
        label: '全部用户',
        key: '1'
      },
      {
        label: '已指定科室',
        key: '2'
      },
      {
        label: '需指定科室',
        key: '3'
      }
    ]
  }),

  methods: {
    add() {
      this.addDialog = true
    },

    tabClick() {
      this.search()
    },

    search() {
      this.tableData = [
        {
          number: '001',
          name: '派大星',
          tel: '110',
          email: '110@0.com',
          roleName: '科室'
        }
      ]
    }
  }
}
</script>
